/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package enteties.person;

import java.util.ArrayList;
import java.util.Collection;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import util.person.TelecomtypeDetails;

/**
 *
 * @author Gebruiker
 */
@Stateless
public class TelecomtypeFacade extends AbstractFacade<Telecomtype> implements TelecomtypeFacadeLocal {
    @PersistenceContext(unitName = "Liebaut-ejbPU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public TelecomtypeFacade() {
        super(Telecomtype.class);
    }
    
    @Override
    public Integer creatTelecomType(String name){
        Telecomtype type = new Telecomtype(name);
        create(type);
        return type.getId();
    }
    
    @Override
    public void editTelecomType(Integer id, String name){
        Telecomtype type = find(id);
        type.setName(name);
        edit(type);
    }
    
    @Override
    public void removeTelecomType(Integer id){
        Telecomtype type = find(id);
        remove(type);
    }
    
    @Override
    public TelecomtypeDetails findById(Integer id){
        return convert(find(id));
    }
    
    @Override
    public Collection<TelecomtypeDetails> findAllTypes(){
        Collection<TelecomtypeDetails> types = new ArrayList<TelecomtypeDetails>();
        for(Telecomtype type:findAll()){
            types.add(convert(type));
        }
        return types;
    }
    
    public TelecomtypeDetails convert(Telecomtype type){
        return new TelecomtypeDetails(type.getId(), type.getName());
    }
    
}
